/* ================================================================
*   Copyright (C) 2020 All rights reserved.
*
*   文件名称：read_example.cpp
*   创 建 者：xunmenglong
*   创建日期：2020年12月06日
*   描    述：
*
================================================================ */


#ifndef READ_EXAMPLE_CPP
#define READ_EXAMPLE_CPP

#include "xkvstore.h"

int main(int argc, char ** argv) {
    xkvstore kv;
    int ret = kv.init("./data");
    if (ret != 0) {
        LOG(ERROR) << "xkvstore init fail";
        return -1;
    }
    uint64_t keys[7] = {10000, 10001, 10002, 10003, 10004, 11111, 22222};
    char * value_ptr = (char *)malloc(10240);
    int value_len = 0;
    for (int i=0; i<7; i++) {
        int key = keys[i];
        ret = kv.get(key, value_ptr, &value_len);
        if (ret == 0) {
            LOG(NOTICE) << "read [" << key << "]: " << value_ptr
                << ", value_len: " << value_len;
        } else if (ret == 1) {
            LOG(NOTICE) << "read [" << key << "]: not exists";
        } else {
            LOG(ERROR) << "read [" << key << "]: fail";
            return -1;
        }
    }
    return 0;
}

#endif
